package com.ruoyi.system.service.impl;


import com.ruoyi.system.domain.SysHousehold;
import com.ruoyi.system.domain.UserRegister;
import com.ruoyi.system.mapper.SysHouseholdMapper;
import com.ruoyi.system.mapper.UserRegisterMapper;
import com.ruoyi.system.service.ISysHouseholdService;
import com.ruoyi.system.service.IUserRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserRegisterServiceImpl implements IUserRegisterService {

    @Autowired
    private UserRegisterMapper userRegisterMapper;

    @Autowired
    private SysHouseholdMapper sysHouseholdMapper;

    @Autowired
    private ISysHouseholdService sysHouseholdService;

    @Override
    public void addUser(UserRegister userRegister) {

        String phone = userRegister.getPhone();
        String name = userRegister.getName();
        Integer sex = userRegister.getSex();
        String weChat = userRegister.getWeChat();
        Long community = userRegister.getCommunity();
        Long building = userRegister.getBuilding();
        String address = userRegister.getAddress();

        SysHousehold household = new SysHousehold();
        household.setName(name);
        household.setPhone(phone);
        household.setCommunity(community);
        household.setBuilding(building);
        household.setAddress(address);

        sysHouseholdMapper.insertSysHousehold(household);
        Long id = household.getId();

        UserRegister user1 = new UserRegister();
        user1.setName(name);
        user1.setPhone(phone);
        user1.setWeChat(weChat);
        user1.setPassword("123456");
        user1.setSex(sex);
        user1.setCommunity(community);
        user1.setBuilding(building);
        user1.setAddress(address);

        Long aLong = Long.valueOf(id);
        user1.setHouse_id(aLong);

        userRegisterMapper.addUser(user1);


    }


}
